layui.use(['laydate','form','table','laytpl','layer'], function(){
	var laydate = layui.laydate;
	var form = layui.form;
	var table = layui.table;
	var laytpl = layui.laytpl;
	var layer = layui.layer;
	var list_url = '/user/repair/index';
	var count_url = '/repair/repair/count_repair';

	var usn = $('input[name="user_sn"]').val();
	//执行一个laydate实例
	laydate.render({
	  	elem: '#start' //指定元素
	});

	//执行一个laydate实例
	laydate.render({
	  	elem: '#end' //指定元素
	});
	/*@初始化table*/
	var tableObj = table.render({
	    elem: '#table-list',
	    url: list_url, //数据接口
	    page: true, //开启分页
	    where: {user_sn:usn},
	    cols: [[ //表头
	    	{field: 'repair_id', title: '序号'},
	    	{field: 'addtime', title: '时间'},
	    	{field: 'repair_sn', title: '维修编号'},
	    	{field: 'username', title: '客户姓名'},
	    	{field: 'phone', title: '联系方式'},
	    	{field: 'user_sn', title: '客户编号'},
	    	{field: 'gname', title: '产品名称'},
	    	{field: 'imei', title: 'IMEI'},
	    	{field: 'sn', title: 'S/N'},
	    	{field: 'repair_money', title: '维修费'},
	    	{field: 'admin_nkname', title: '营业员'},
	    	{field: 'tech_nkname', title: '维修员'},
	    	{title: '操作', width: 100,toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'查看详情\',\'/user/repair/repair_details/ids/{{d.repair_id}}\')">查看详情</a></div>'},
	    ]],
	    parseData: function(res){
	    	let con = res.data.count
	    	res.data = res.data.list
	    	var getTpl = table_count.innerHTML
			var view = document.getElementById('list-count');
			laytpl(getTpl).render(con, function(html){
			  	view.innerHTML = html;
			});
	    },
	});
	/*@查询*/
	form.on('submit(search)',function(data){
		if(data.field.start != '' && data.field.end != ''){
			var startDate = new Date(data.field.start).getTime();
			var endDate = new Date(data.field.end).getTime();
			if(startDate > endDate){
				layer.msg('开始时间不能大于结束时间',{icon: 2})
				return false
			}
		}
		/*重置表格数据*/
		tableObj.reload({
			page: {
                page: 1 //重新从第 1 页开始
            },
            where: data.field
        });
        return false
	})
	
});